package com.dk.controller;
import com.dk.pojo.TProduct;
import com.dk.pojo.TType;
import com.dk.service.TProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@RequestMapping("to")
public class TProductController {
    @Autowired
    private TProductService tProductService;
    //展示页面
    @RequestMapping("toshow")
    public String toShow(){
        return "show";
    }
    //查询
    @RequestMapping("getInfo")
    @ResponseBody
    public PageInfo<TProduct> selectAll(@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "3")Integer pageSize,TProduct tProduct){
        PageInfo<TProduct> page = tProductService.selectAll(pageNum,pageSize,tProduct);
        return page;
    }
    //删除
    @RequestMapping("deleteS")
    public String deleteS(String[] ids){
        tProductService.deleteS(ids);
        return "redirect:/controller/selectS";
    }
    //回显
    @RequestMapping("Echo1")
    public String Echo1(Integer id,Model m){
        TProduct t = tProductService.selectId(id);
        List<TType> list = tProductService.selectType();
        System.out.println(t);
        m.addAttribute("list",list);
        m.addAttribute("t",t);
        return "Echo";
    }
    //修改
    @RequestMapping("update")
    @ResponseBody
    public Integer update(TProduct t){
        Integer i = tProductService.updateBy(t);
        return i;
    }
    //进入增加页面
    @RequestMapping("add")
    public String insertS(Model m) {
        List<TType> list = tProductService.selectType();
        System.out.println("add方法进入");
        m.addAttribute("list", list);
        return "add";
    }
    //增加

}